package com.abyss;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.operators.MapOperator;
import org.apache.flink.core.fs.FileSystem;

/**
 * 不使用累加器的场景
 */
public class AccumulatorDemo1 {
    public static void main(String[] args) throws Exception {
        // 1. Env
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        // 2. Source
        DataSource<Long> source = env.generateSequence(1, 10);

        MapOperator<Long, Long> map = source.map(new MapFunction<Long, Long>() {
            private long counter = 0;

            @Override
            public Long map(Long value) throws Exception {
                counter++;
                System.out.println("current: " + counter);
                return value;
            }
        });

        map.writeAsText("/Users/abyss/Dev/toys/flink/H-flink-learn/src/main/resources/ac1", FileSystem.WriteMode.OVERWRITE);
        env.execute();
    }
}